var express = require('express');
var router = express.Router();
let { UserModel } = require('../db/model') 


// 用户添加接口
router.post('/addUser',async (req,res)=>{
  let body = req.body;
  let data = await UserModel.find({}).lean();
  data.forEach(item=>{
    if(item.username === body.username){
      res.send({
        code:404,
        msg:'该用户已注册'
      })
    }
  })
    await UserModel.create({
      username: body.username,
      password: body.password
    })
    res.send({
      code:200,
      msg:'添加成功'
    })

})

module.exports = router;
